package L1.L1_005;

import java.util.Scanner;

class StudentInfo{
    String identify;
    int test_id;
    int seat_id;
}

public class Main {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        int N = reader.nextInt();
        StudentInfo []Infos = new StudentInfo[N];
        for(int i=0;i<N;i++){
            Infos[i] = new StudentInfo();
            Infos[i].identify = reader.next();
            if(Infos[i].identify.length() != 16){
                System.out.println("准考证输入不正确");
                continue;
            }
            Infos[i].test_id = reader.nextInt();
            Infos[i].seat_id = reader.nextInt();
        }
        int M = reader.nextInt();
        int [] tid = new int[M];
        for(int j=0;j<M;j++){
            tid[j] = reader.nextInt();
        }
        int pos;
        for(int k = 0;k<M;k++){
            pos = Search(tid[k],Infos);
            System.out.printf("%s %d\n",Infos[pos].identify,Infos[pos].seat_id);
        }

    }

    private static int Search(int pos,StudentInfo Infos[]) {
        for (int i = 0; i < Infos.length; i++) {
            if (Infos[i].test_id == pos)
                return i;
        }
        return -1;
    }

}

